<template>
  <d2-container>
    <el-form :model="FormSearch" status-icon label-width="100px" class="demo-ruleForm">
      <el-row :gutter="24">
        <el-col :span="5">
          <el-form-item label="条件查找">
            <el-date-picker
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择开始时间"
            v-model="FormSearch.startTime"
            style="width: 100%;"
          ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-date-picker
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择结束时间"
            v-model="FormSearch.endTime"
            style="width: 100%;"
          ></el-date-picker>
        </el-col>
        <el-col :span="5">
          <el-button type="primary" @click="searchClick()">查询</el-button>
          <el-button @click="resetForm()">重置</el-button>
        </el-col>
      </el-row>
    </el-form>
    <!-- 数据表格 -->
    <d2-crud
      ref="d2Crud"
      :columns="columns"
      :data="data"
      :pagination="page"
      @pagination-current-change="paginationCurrentChange"
    />
  </d2-container>
</template>

<script>
import { getOrderStatistics } from "@/api/goods/index";
import util from '@/libs/util.js'

export default {
  data() {
    return {
      // 搜索数据
      FormSearch: {
        startTime: "",
        endTime: "",
      },
      // 字段名称
      columns: [
        {
          title: "订单号",
          key: "code",
          align: "center"
        },
        {
          title: "开始时间",
          key: "create_time",
          align: "center"
        },
        {
          title: "维修组id",
          key: "z_id",
          align: "center"
        },
        {
          title: "结束时间",
          key: "end_time",
          align: "center"
        },
        {
          title: "类型",
          key: "state",
          align: "center"
        },
        {
          title: "所属人ID",
          key: "work_id",
          align: "center"
        },
        {
          title: "备注",
          key: "remark",
          align: "center"
        },
      ],
      // 列表数据
      data: [],
      // 分页数据
      page: {
        total: 0,
        pageIndex: 1,
        pageSize: 10
      }
    };
  },
  created() {
    let params = {
      page: this.page.pageIndex,
      limit: this.page.pageSize,
    };
    this.init(params);
  },
  methods: {
    // 初始化身体数据列表
    init(params) {
      params.cjId = util.cookies.get('roleid')
      params.orderType = 1
      getOrderStatistics(params)
        .then(res => {
          if (res.success) {
            this.data = res.rows;
            this.page.total = res.total;
          }
        })
        .catch(err => {
          this.$message.error(err);
        });
    },

    // 分页数改变，调用
    paginationCurrentChange(pageIndex) {
      let params = {
        limit: this.page.pageSize,
        good: this.FormSearch.good
      };
      params.page = this.page.pageIndex = pageIndex;
      this.init(params);
    },

    // 条件查询搜索
    searchClick() {
      let params = {};
      params = this.FormSearch;
      params.page = 1;
      console.log(params);
      this.init(params);
    },

    // 重置查询
    resetForm() {
      this.FormSearch.good = "";
      let params = {
        page: 1,
        limit: 10
      };
      this.init(params);
    }
  }
};
</script>

<style lang="scss" scoped>
</style>